package com.gwcloud.leetcode.tags.tree;

/** 
* @ClassName   : Leetcode0167 
* @author      : ganwei 
* @date        : 2020年6月17日 
* @Description : TODO 
*/
public class Leetcode0167 {
	/**
	 * -解题思路
	 */
    public int[] twoSum(int[] numbers, int target) {
    	int start = 0, end = numbers.length-1;
    	int[] res = new int[2];
    	while(start < end) {
    		if(target == numbers[start]+numbers[end]) {
    			res[0] = start + 1;
    			res[1] = end + 1;
    			return res;
    		}else if(numbers[start]+numbers[end] > target) {
    			end--;
    		}else {
    			start++;
    		}
    	}
    	return res;
    }
    /**
     * -主函数
     */
    public static void main(String[] args) {
    	Leetcode0167 l0167 = new Leetcode0167();
    	int[] numbers = {2,7,11,15};
    	System.out.println(l0167.twoSum(numbers, 9));
    			
    }
}
